package com.example.mall.web.controller;

import com.example.mall.domain.UserOrderRecords;
import com.example.mall.dto.UserOrderRecordsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.UserOrderRecordsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IUserOrderRecordsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userOrderRecords")
public class UserOrderRecordsController {

    @Autowired
    public IUserOrderRecordsService userOrderRecordsService;

    /**
     * 分页查询用户下单记录表信息
     * @param userOrderRecordsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询用户下单记录表信息",notes = "分页查询用户下单记录表信息",httpMethod = "GET")
    public JSONResult queryPage(UserOrderRecordsQuery userOrderRecordsQuery){
        PageDTO<UserOrderRecordsDto> userOrderRecordsDtoPageDTO = userOrderRecordsService.queryPage(userOrderRecordsQuery);
        return JSONResult.success("查询成功",userOrderRecordsDtoPageDTO);
    }

    /**
     * 根据id查询用户下单记录表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询用户下单记录表信息",notes = "根据id查询用户下单记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.RECORDID_NOT_ID);
        }
        UserOrderRecords userOrderRecords = userOrderRecordsService.getById(id);
        return JSONResult.success("查询成功",userOrderRecords);
    }

    /**
     * 根据id查询用户下单记录表信息
     * @param id
     * @return
     */
    @GetMapping("queryUserOrderRecordsById/{id}")
    @ApiOperation(value = "根据id查询用户下单记录表信息",notes = "根据id查询用户下单记录表信息",httpMethod = "GET")
    public JSONResult queryUserOrderRecordsById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.RECORDID_NOT_ID);
        }
        UserOrderRecords userOrderRecords = userOrderRecordsService.queryUserOrderRecordsById(id);
        return JSONResult.success("查询成功",userOrderRecords);
    }

    /**
     * 查询全部用户下单记录表信息
     * @param
     * @return
     */
    @GetMapping("queryUserOrderRecordsList")
    @ApiOperation(value = "查询全部用户下单记录表信息",notes = "查询全部用户下单记录表信息",httpMethod = "GET")
    public JSONResult queryUserOrderRecordsList(){
        List<UserOrderRecords> userOrderRecords = userOrderRecordsService.queryUserOrderRecordsList();
        return JSONResult.success("查询成功",userOrderRecords);
    }

    /**
     * 新增用户下单记录表
     * @param userOrderRecordsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增用户下单记录表",notes = "新增用户下单记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody UserOrderRecordsDto userOrderRecordsDto){
        userOrderRecordsService.insert(userOrderRecordsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改用户下单记录表信息
     * @param userOrderRecordsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改用户下单记录表信息",notes = "修改用户下单记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody UserOrderRecordsDto userOrderRecordsDto){
        userOrderRecordsService.update(userOrderRecordsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除用户下单记录表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除用户下单记录表信息",notes = "删除用户下单记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        userOrderRecordsService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除用户下单记录表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除用户下单记录表信息",notes = "批量删除用户下单记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        userOrderRecordsService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
